home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / c_wndw.zip / HASHTEST.C < prev    next >
Text File  |  1989-05-25  |  3KB  |  85 lines

  1. /*  (c) Marietta Systems, Inc.  1987
  2. *    All rights reserved
  3. *
  4. *    Test program for hashed files functions
  5. */
  6. #include "mtest.h"
  7. void main(){
  8. long rec_nbr;
  9. int fh2, z, x, k;
  10. byte input[30], key[17];
  11. clr_scrn("Filewrit access test");
  12. KEYMATCH[0] = KEYMATCH[1] = 0;
  13. KEYMATCH[4] = 0XB000; 
  14. disp_err("",1); /* activate AMEND, INSERT, DELETE keys */
  15. /*  
  16. *    Create hashed file 
  17. */
  18. if (disp_qry(" Create the hashed file"))
  19.     fh2 = hashmake("testfile.hsh", 10, 64, 200L, 5, 16);
  20.     else fh2 = fileopen("testfile.hsh", hashed, update);
  21. if (fh2 <= 0) goodbye (106); /* open error */
  22. while (!disp_qry(" Ready to random read/write"));
  23. /*    
  24. *     Read the hashed file
  25. */
  26. display ("File opened - records can be read", 1, 40, low);
  27. display ("Next record key", 4, 1, high);
  28. rec_nbr = 1L; FN[fh2].record[64] = 0; key[0] = 0;
  29. for (;;){
  30.     set_crsr(4, 17);
  31.     if (0 > accept(key, left, alt_reverse, 16, 0)) goodbye(101); 
  32.     if (INCHAR == QUIT) break;
  33.     if (INCHAR == INSERT) x = 1; else x = 0;
  34.     rec_nbr = hashread(fh2, key, x);
  35.     if (rec_nbr < 1L) {disp_err("Press F5 key to insert new record", 1); 
  36.     continue;}
  37.     switch (INCHAR){
  38.         case DELETE: display(&FN[fh2].record[22], 7, 4, alt_low);
  39.             if (disp_qry("Do you want to delete the record"))
  40.                 {FN[fh2].record[0] = DELETED;
  41.                 filewrit(fh2, &rec_nbr);
  42.                 FN[fh2].r_count -= 1L;
  43.                 disp_err("Record deleted", 1013);}
  44.             break;
  45.        case INSERT: memset(&FN[fh2].record[1], 32, FN[fh2].rec_len - 1);
  46.             memcpy(&FN[fh2].record[5], key, 16);
  47.             disp_err("Record Insert mode", 1);
  48.        case AMEND: set_crsr(7,4);
  49.             accept(&FN[fh2].record[22], as_typed, alt_reverse, 40, 0);
  50.             if (INCHAR == QUIT) {INCHAR = ENTER; break;}
  51.             if (FN[fh2].record[0] != IN_USE) {FN[fh2].record[0] = IN_USE;
  52.                 FN[fh2].r_count += 1L;}
  53.             filewrit(fh2, &rec_nbr);
  54.             break;
  55.        default: display(&FN[fh2].record[22], 7, 4, alt_low);
  56.                break;
  57.        } /* end switch */
  58.    } /* end for */
  59. if (fileclos(fh2) < 1) goodbye(109);
  60. /*
  61. *     Scan through hashed file to analyse usage
  62. */
  63. while(!disp_qry(" Ready to analyse hashed file"));
  64. clr_wndw(); 
  65. k = x = z = 0;
  66. if (fileclos(fh2) < 0) goodbye (110);
  67. if ((fh2 = fileopen("testfile.hsh", hashed, readonly)) <= 0) goodbye(111);
  68. while(fileread(fh2, nextrec, &rec_nbr) > 0){
  69.     if (FN[fh2].record[0] == EMPTY) {k++; continue;}
  70.     if (FN[fh2].record[0] == DELETED) {z++; continue;}
  71.     if (FN[fh2].record[0] != IN_USE) 
  72.         {disp_err("corrupted record",1); goodbye(2);}
  73.     display(&FN[fh2].record[5],++x,1,alt_low);
  74.     if (!(x & 0XF)) idleloop(36);
  75.     }
  76. mk_wndw(10, 25, 16, 55, "Analysis of file");
  77. sprintf(input, " %3u records in use  ", x); display(input, 1, 4, reverse); 
  78. sprintf(input, " %3u records deleted ", z); display(input, 2, 4, reverse); 
  79. sprintf(input, " %3u records empty   ", k); display(input, 3, 4, reverse); 
  80. sprintf(input, " %3lu r_count value  ", FN[fh2].r_count); 
  81.     display(input, 5, 4, alt_reverse); 
  82. disp_msg(" Press any key to end", 1); read_kb();
  83. goodbye(0);
  84. }
  85.